//
//  MSMeTopView.m
//  MS
//
//  Created by He Yuan on 13-2-21.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSUserHomePageTopView.h"
#import "UIButton+WebCache.h"
#import <QuartzCore/QuartzCore.h>
#import "UIColor+ColorUtils.h"

@implementation MSUserHomePageTopView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"me_top_bg"]];
        
        self.frame = frame;
        
        CGRect avatarFrame = CGRectMake(10,17,65,65);
        avatarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [avatarBtn setImage:[UIImage imageNamed:@"default_img@2x.png"] forState:UIControlStateNormal];
        avatarBtn.layer.cornerRadius = 2.0;
        avatarBtn.layer.masksToBounds = YES;
        avatarBtn.layer.borderWidth = 2;
        avatarBtn.layer.borderColor = [UIColor colorWithWhite:0.912 alpha:1.000].CGColor;
        [avatarBtn setFrame:avatarFrame];
        [self addSubview:avatarBtn];
        
        UIImageView *authImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me_hairdress"]];
        [self addSubview:authImageView];
        authImageView.center = CGPointMake(avatarFrame.size.width+avatarFrame.origin.x-4, avatarFrame.size.height+avatarFrame.origin.y-4);
        
        CGFloat offset_x = avatarBtn.frame.size.width+avatarBtn.frame.origin.x + 6;
        
        nameLbl = [MSTool createLable:CGRectMake(offset_x,14,self.frame.size.width - offset_x,25)];
        [nameLbl setTextColor:[UIColor darkGrayColor]];
        [nameLbl setBackgroundColor:[UIColor clearColor]];
        [nameLbl setText:HYLocalizedString(@"")];
        [nameLbl setTextAlignment:UITextAlignmentLeft];
        [self addSubview:nameLbl];
        
        

    }
    return self;
}

-(void)refreshUI:(NSDictionary *)info
{
    HYLog(@"info--->%@",info);
    if (info && [info isKindOfClass:[NSDictionary  class]])
    {
        if ([info objectForKey:@"avatar"])
        {
            [avatarBtn setImageWithURL:[NSURL URLWithString:[info objectForKey:@"avatar"]] forState:UIControlStateNormal];
        }
        
        if ([info objectForKey:@"user_name"]) {
            nameLbl.text = [info objectForKey:@"user_name"];
        }
    }
}




/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

@end
